<!DOCTYPE html>
<html class="x-admin-sm">
{include file='public/header'}
<meta name="referrer" content="never">
<style>
    .layui-form-item{clear: none;}
    .layui-form img{width: 150px;height: 150px;display: none;}
    .layui-form-label{width: 100px;}
    .layui-input-block{margin-left: 130px;}
    .layui-elem-field .layui-form-label{width: 160px;}
    .layui-elem-field .layui-input-block{margin-left: 190px;}
    #categories,#privacy{display: flex;align-items: center;}
</style>
<body>
    <div class="x-body">
        <form class="layui-form layui-row" lay-filter="formAjax">
            <div class="layui-form-item layui-col-md4">
                <label class="layui-form-label">头像：</label>
                <div class="layui-input-block">
                    <img onclick="showimg(this)" src="" id="head_img" alt="">
                </div>
            </div>
            <div class="layui-form-item layui-col-md4">
                <label class="layui-form-label">二维码：</label>
                <div class="layui-input-block">
                    <img onclick="showimg(this)" src="" id="qrcode_url" alt="">
                </div>
            </div>
            <div class="layui-form-item layui-col-md4">
                <label class="layui-form-label">体验版：</label>
                <div class="layui-input-block">
                    <img onclick="showimg(this)" src="" id="QrCode" alt="">
                </div>
            </div>
            <div class="layui-form-item layui-col-md6">
                <label class="layui-form-label">昵称：</label>
                <div class="layui-input-block">
                    <input type="text" name="nick_name" disabled class="layui-input">
                </div>
            </div>
            <div class="layui-form-item layui-col-md6">
                <label class="layui-form-label">主体名称：</label>
                <div class="layui-input-block">
                    <input type="text" name="principal_name" disabled class="layui-input">
                </div>
            </div>
            <div class="layui-form-item layui-col-md12">
                <label class="layui-form-label">小程序介绍：</label>
                <div class="layui-input-block">
                    <input type="text" name="signature" disabled class="layui-input">
                </div>
            </div>
            <div class="layui-form-item layui-col-md12">
                <label class="layui-form-label">类目：</label>
                <div class="layui-input-block" id="categories"></div>
            </div>
            <fieldset class="layui-elem-field layui-field-title">
                <legend>合法域名信息</legend>
                <div class="layui-field-box">
                    <div class="layui-form-item layui-col-md12">
                        <label class="layui-form-label">request合法域名：</label>
                        <div class="layui-input-block">
                            <input type="text" name="RequestDomain" disabled class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item layui-col-md12">
                        <label class="layui-form-label">socket合法域名：</label>
                        <div class="layui-input-block">
                            <input type="text" name="WsRequestDomain" disabled class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item layui-col-md12">
                        <label class="layui-form-label">uploadFile合法域名：</label>
                        <div class="layui-input-block">
                            <input type="text" name="UploadDomain" disabled class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item layui-col-md12">
                        <label class="layui-form-label">downloadFile合法域名：</label>
                        <div class="layui-input-block">
                            <input type="text" name="DownloadDomain" disabled class="layui-input">
                        </div>
                    </div>
                </div>
            </fieldset>
            <fieldset class="layui-elem-field layui-field-title">
                <legend>用户隐私保护指引</legend>
                <div class="layui-field-box">
                    <div class="layui-form-item layui-col-md12">
                        <label class="layui-form-label">用户隐私保护：</label>
                        <div class="layui-input-block" id="privacy"></div>
                    </div>
                    <div class="layui-form-item layui-col-md12">
                        <label class="layui-form-label">手机号：</label>
                        <div class="layui-input-block">
                            <input type="text" name="contact_phone" disabled class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item layui-col-md12">
                        <label class="layui-form-label">邮箱地址：</label>
                        <div class="layui-input-block">
                            <input type="text" name="contact_email" disabled class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item layui-col-md12">
                        <label class="layui-form-label">qq号：</label>
                        <div class="layui-input-block">
                            <input type="text" name="contact_qq" disabled class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item layui-col-md12">
                        <label class="layui-form-label">微信号：</label>
                        <div class="layui-input-block">
                            <input type="text" name="contact_weixin" disabled class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item layui-col-md12">
                        <label class="layui-form-label">存储期限：</label>
                        <div class="layui-input-block">
                            <input type="text" name="store_expire_timestamp" disabled class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item layui-col-md12">
                        <label class="layui-form-label">通知方式：</label>
                        <div class="layui-input-block">
                            <input type="text" name="notice_method" disabled class="layui-input">
                        </div>
                    </div>
                </div>
            </fieldset>
            <fieldset class="layui-elem-field layui-field-title">
                <legend>小程序版本信息-线上</legend>
                <div class="layui-field-box">
                    <div class="layui-form-item layui-col-md12">
                        <label class="layui-form-label">最低基础库：</label>
                        <div class="layui-input-block">
                            <input type="text" name="now_version" disabled class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item layui-col-md12">
                        <label class="layui-form-label">发布时间：</label>
                        <div class="layui-input-block">
                            <input type="text" name="release_time" disabled class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item layui-col-md12">
                        <label class="layui-form-label">版本信息：</label>
                        <div class="layui-input-block">
                            <input type="text" name="release_version" disabled class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item layui-col-md12">
                        <label class="layui-form-label">版本描述：</label>
                        <div class="layui-input-block">
                            <input type="text" name="release_desc" disabled class="layui-input">
                        </div>
                    </div>
                </div>
            </fieldset>
            <fieldset class="layui-elem-field layui-field-title">
                <legend>小程序版本信息-最新一次审核单状态</legend>
                <div class="layui-field-box">
                    <div class="layui-form-item layui-col-md6">
                        <label class="layui-form-label">审核单号：</label>
                        <div class="layui-input-block">
                            <input type="text" name="auditid" disabled class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item layui-col-md6">
                        <label class="layui-form-label">审核时间：</label>
                        <div class="layui-input-block">
                            <input type="text" name="submit_audit_time" disabled class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item layui-col-md6">
                        <label class="layui-form-label">审核版本：</label>
                        <div class="layui-input-block">
                            <input type="text" name="user_version" disabled class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item layui-col-md6">
                        <label class="layui-form-label">审核状态：</label>
                        <div class="layui-input-block">
                            <input type="text" name="status" disabled class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item layui-col-md12">
                        <label class="layui-form-label">版本描述：</label>
                        <div class="layui-input-block">
                            <input type="text" name="user_desc" disabled class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item layui-col-md12">
                        <label class="layui-form-label">拒绝原因：</label>
                        <div class="layui-input-block">
                            <textarea name="reason" disabled class="layui-textarea"></textarea>
                        </div>
                    </div>
                </div>
            </fieldset>
            
        </form>
    </div>
    <script>
        layui.use(["form", "layer"], function () {
            var form = layui.form,
                layer = layui.layer;
            let app_id = GetQueryString('app_id')   
            // 获取授权方的帐号基本信息
            let getAuthorizer = new Promise((resolve)=>{
                Ajax('/admin/OpenWeixin/getAuthorizer',{app_id},'get').then(result =>{
                    resolve(flattenObject(result.data))
                });
            })
            
            // 查询小程序版本信息
            let getVersionInfo = new Promise((resolve)=>{
                Ajax('/admin/OpenWeixin/getVersionInfo',{app_id},'get').then(result =>{
                    result.data.release_time = dayjsFormat(result.data.release_info.release_time)
                    resolve(flattenObject(result.data))
                });
            })

            // 获取体验版二维码
            let getQrCode = new Promise((resolve)=>{
                Ajax('/admin/OpenWeixin/getQrCode',{app_id},'get').then(result =>{
                    resolve(flattenObject(result.data))
                });
            })

            // 获取版本库
            let getSupportVersion = new Promise((resolve)=>{
                Ajax('/admin/OpenWeixin/getSupportVersion',{app_id},'get').then(result =>{
                    resolve(flattenObject(result.data))
                });
            })

            // 查询最新一次审核单状态
            let getLatestAuditStatus = new Promise((resolve)=>{
                Ajax('/admin/OpenWeixin/getLatestAuditStatus',{app_id},'get').then(result =>{
                    result.data.submit_audit_time = dayjsFormat(result.data.submit_audit_time)
                    result.data.status = ['审核成功','审核被拒绝','审核中','已撤回','审核延后'][result.data.status]
                    resolve(result.data)
                });
            })

            // 获取小程序用户隐私保护指引
            let getPrivacySetting = new Promise((resolve)=>{
                Ajax('/admin/OpenWeixin/getPrivacySetting',{app_id},'get').then(result =>{
                    // 用户隐私
                    let privacy = ''
                    result.data.setting_list.forEach(item=>{
                        privacy += `<span class="layui-badge layui-bg-green" style='margin-right:8px'>${item.privacy_key}-${item.privacy_text}</span>`
                    })
                    $("#privacy").html(privacy)
                    resolve(flattenObject(result.data))
                });
            })
            
            Promise.all([getAuthorizer,getVersionInfo,getQrCode,getLatestAuditStatus,getSupportVersion,getPrivacySetting].map(p=>{
                return p.then(e=> {
                    return p
                })
            })).then((dataArray)=>{
                let getAuthorizerResult = dataArray[0]
                let getVersionInfoResult = dataArray[1]
                let getQrCodeResult = dataArray[2]
                let getLatestAuditStatusResult = dataArray[3]
                let getSupportVersionResult = dataArray[4]
                let getPrivacySettingResult = dataArray[5]
                // 域名
                getAuthorizerResult.RequestDomain = getAuthorizerResult.network.RequestDomain;
                getAuthorizerResult.WsRequestDomain = getAuthorizerResult.network.WsRequestDomain;
                getAuthorizerResult.UploadDomain = getAuthorizerResult.network.UploadDomain;
                getAuthorizerResult.DownloadDomain = getAuthorizerResult.network.DownloadDomain;

                // 设置图片
                $('#head_img').attr('src',getAuthorizerResult.head_img).show()
                $('#qrcode_url').attr('src',getAuthorizerResult.qrcode_url).show()
                $('#QrCode').attr('src','data:image/gif;base64,'+getQrCodeResult.image).show()

                // 设置类目
                let categories = ''
                getAuthorizerResult.categories.forEach(item=>{
                    categories += `<span class="layui-badge layui-bg-green" style='margin-right:8px'>${item.first}-${item.second}</span>`
                })
                $("#categories").html(categories)

                form.val("formAjax",{...getAuthorizerResult,...getVersionInfoResult,...getLatestAuditStatusResult,...getSupportVersionResult,...getPrivacySettingResult});   
            })
        });


        function flattenObject(obj) {
            var result = {};
            for (var key in obj) {
                if (obj.hasOwnProperty(key)) {
                    if (typeof obj[key] === 'object' && obj[key] !== null && key != 'categories' && key != 'network') {
                        var flattenedObj = flattenObject(obj[key]);
                        for (var prop in flattenedObj) {
                            if (flattenedObj.hasOwnProperty(prop)) {
                                result[prop] = flattenedObj[prop];
                            }
                        }
                    } else {
                        result[key] = obj[key];
                    }
                }
            }
            return result;
        }
    </script>
</body>

</html>